package com.stylefeng.guns.modular.record.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.CarRecord;
import com.stylefeng.guns.modular.record.service.ICarRecordService;

/**
 * 当日记录控制器
 *
 * @author fengshuonan
 * @Date 2018-08-22 10:58:28
 */
@Controller
@RequestMapping("/carRecord")
public class CarRecordController extends BaseController {

    private String PREFIX = "/record/carRecord/";

    @Autowired
    private ICarRecordService carRecordService;

    /**
     * 跳转到当日记录首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "carRecord.html";
    }

    /**
     * 跳转到添加当日记录
     */
    @RequestMapping("/carRecord_add")
    public String carRecordAdd() {
        return PREFIX + "carRecord_add.html";
    }

    /**
     * 跳转到修改当日记录
     */
    @RequestMapping("/carRecord_update/{carRecordId}")
    public String carRecordUpdate(@PathVariable Integer carRecordId, Model model) {
        CarRecord carRecord = carRecordService.selectById(carRecordId);
        model.addAttribute("item",carRecord);
        LogObjectHolder.me().set(carRecord);
        return PREFIX + "carRecord_edit.html";
    }

    /**
     * 获取当日记录列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return carRecordService.selectList(null);
    }

    /**
     * 新增当日记录
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(CarRecord carRecord) {
        carRecordService.insert(carRecord);
        return SUCCESS_TIP;
    }

    /**
     * 删除当日记录
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer carRecordId) {
        carRecordService.deleteById(carRecordId);
        return SUCCESS_TIP;
    }

    /**
     * 修改当日记录
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(CarRecord carRecord) {
        carRecordService.updateById(carRecord);
        return SUCCESS_TIP;
    }

    /**
     * 当日记录详情
     */
    @RequestMapping(value = "/detail/{carRecordId}")
    @ResponseBody
    public Object detail(@PathVariable("carRecordId") Integer carRecordId) {
        return carRecordService.selectById(carRecordId);
    }
}
